home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group94a.txt
/
000079_icon-group-sender _Tue Apr 5 08:26:42 1994.msg
< prev
next >
Wrap
Internet Message Format
|
1994-08-19
|
1KB
Received: by cheltenham.cs.arizona.edu; Tue, 5 Apr 1994 09:01:47 MST
Date: Tue, 5 Apr 1994 08:26:42 +0700
From: swampler@noao.edu
Message-Id: <9404051526.AA04963@orpheus.tuc.noao.edu>
Subject: Re: 2d arrays in Icon
To: icon-group@cs.arizona.edu
Content-Length: 690
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
In addition to Chris' approach using a table (which is also *very* nice for
sparse arrays), it's pretty easy to write a 2d array 'constructor' function:
procedure array2d(num_rows, num_cols)
local a
a := list(num_rows)
every !a := list(num_cols)
return a
end
You can then reference the result, as in:
board := array2d(8, 8)
board[1][1] := "Q"
One nice thing about 2d-arrays in Icon is that they are, indeed, dynamic
(since they are just constructed from lists) - it's not hard to write functions
to grow/shrink them, insert/remove columns/rows, etc. (columns are harder than
rows...)
--
Steve Wampler
swampler@noao.edu
Gemini Project (under AURA)